<template>
	<view class="pages">
		<!-- 这里是状态栏 -->
		<view class="status_bar"></view>
		<view class="title">注册 <text class='right' @click="gopage('/pages/login/login')">登录 &gt</text></view>
		<view class="content">
			<image class="loginHT" src="../../static/cut/loginHT.png" mode=""></image>
			<view class="from">
				<view class="inputRow">
					<input type="text" placeholder="企业名称" v-model="company" placeholder-style="color:#666666" />
				</view>
				<view class="inputRow">
					<input type="text" placeholder="手机号" v-model="account" placeholder-style="color:#666666" />
				</view>
				<view class="inputRow">
					<input class='Code' type="text" v-model="code" placeholder="验证码" placeholder-style="color:#666666" />
					<text class='sendCode' @click="sendCode" v-if="!sendCodeStu">获取验证码</text>
					<text class='sendCode' v-if="sendCodeStu">{{time}}后获取</text>
				</view>
				<view class="inputRow">
					<input type="text" v-model="password" password="password" placeholder="密码" placeholder-style="color:#666666" />
				</view>
				<view class="inputRow">
					<input type="text" v-model="Rpassword" password="password" placeholder="再次确认密码" placeholder-style="color:#666666" />
				</view>
				<view class="inputRow">
					<input type="text" v-model="parent_id" placeholder="邀请人ID" placeholder-style="color:#666666" />
				</view>
				<view class="zhuce" @click="doRegister">确认注册</view>
			</view>
		</view>
	</view>
</template>

<script>
	import API from '../../common/api.js';
	export default {
		data() {
			return {
				uType:1,//用户类型  1-企业用户  2-供应商
				account:'',//手机号
				password:'',//密码
				Rpassword:'',//确认密码
				code:'',//验证码
				company:'',//企业名称
				parent_id:'',//邀请人ID
				sendCodeStu:false,
				time:60,
				openid:''
			}
		},
		onLoad(option) {
			console.log(JSON.stringify(option))
			if(option.openid){
				this.openid = option.openid;
			}
		},
		methods:{
			doRegister(){
				if(this.password!==this.Rpassword){
					uni.showToast({
						title:"密码不一致",
						icon:"none"
					})
					return false;
				}
				if(this.account&&this.password&&this.code){
					var _this = this;
					uni.request({
						url:API.doRegister,
						data:{
							uType:_this.uType,
							account:_this.account,
							password:_this.password,
							code:_this.code,
							company:_this.company,
							parent_id:_this.parent_id,
							openid:this.openid
						},
						method:"POST",
						header:API.get_head(),
						success: (res) => {
							if(res.data.code==0){
								uni.setStorageSync("userid",res.data.userid);
								uni.setStorageSync("deptid",res.data.deptid);
								uni.setStorageSync("phone",_this.account);
								uni.setStorageSync("vip_status",0);
								uni.switchTab({
									url:'/pages/newpages/home'
								})
							}
							uni.showToast({
								title:res.data.message,
								icon:"none"
							})
						},
						fail: () => {
							uni.showToast({
								title:"加载失败",
								icon:'none'
							})
						}
					})
				}else{
					uni.showToast({
						title:"请完整填写",
						icon:"none"
					})
				}
			},
			sendCode(){
				var _this = this;
				if(!this.checkPhone()){return false}
				_this.sendCodeStu = true
				var T= setInterval(function(){
					_this.time --
					if(_this.time==0){
						 _this.time = 60
						 _this.sendCodeStu = false
						 clearInterval(T)
					}
				},1000)
				uni.request({
					url:API.sendCode,
					data:{tel:_this.account},
					method:"POST",
					header:API.get_head(),
					success: (res) => {
						uni.showToast({
							title:res.data.message,
							icon:"none"
						})
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					}
				})
			},
			checkPhone(){
				if(!(/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.account))){ 
					uni.showToast({
						title:"手机号码错误",
						icon:"none"
					})
					return false; 
				}
				return true; 
			},
			gopage(url){
				uni.navigateTo({
					url:url
				})
			},
		}
	}
	
</script>
	
<style>
	.pages{
		height:100%;
		background-image: url(../../static/cut/rigthHL.jpg);
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}
	.status_bar {
	  height: var(--status-bar-height);
	  width: 100%;
	}
	.title{
		height:98upx;
		text-align: center;
		font-size:36upx;
		line-height:98upx;
		color: #333333;
		position:relative;
	}
	.title .right{color:#FFFFFF;font-size:30upx;position:absolute;right:20upx;top:0;}
	.content{margin-top:20upx;}
	.loginHT{width:263upx;height:284upx;display: block;margin: 0 auto;}
	.from{position: relative;top:-10upx;}
	.inputRow{width:630upx;margin: 0 auto 30upx;background:#f5f5f5;display:flex;}
	.inputRow input{width:586upx;font-size:24upx;padding:20upx 22upx;}
	.inputRow .Code{width:436upx;}
	.inputRow .sendCode{line-height:85upx;width:150upx;font-size:24upx;text-align: center;display: inline-block;color:#439dfc;white-space: nowrap;}
	.zhuce{margin: 0 auto;height:80upx;line-height:80upx;width:630upx;color: #FFFFFF;font-size:30upx;text-align: center;background:#5babfd;}
</style>
